﻿using System;
using System.Diagnostics.Contracts;
using System.Linq;
using OpenWaves.ActivityFeed;
using OpenWaves.ActivityFeed.RavenDB;
using OpenWaves.ActivityFeed.Web;

namespace ActivityFeed.Web.RavenDB
{
    public abstract class RavenActivityFeedBuilder : ActivityFeedBuilder
    {
        protected RavenActivityFeedBuilder(IActivityFeedService activityFeedService, IUpdateDtoBuilder updateDtoBuilder)
            : base(activityFeedService, updateDtoBuilder)
        {
        }

        protected override IQueryable<Update> FilterUpdates(IQueryable<Update> updates)
        {
            return updates.FilterByTopics(this.TopicsFilter);
        }

        protected override IQueryable<Update> SecurityTrimUpdates(IQueryable<Update> updates)
        {
            Contract.Requires<ArgumentNullException>(updates != null);
            return updates.SecurityTrim(this.UserGroups);
        }
    }
}